window.addEventListener('load', function() {
    var hour = this.document.querySelector('hour');
    var minute = this.document.querySelector('minute');
    var second = this.document.querySelector('second');

    var hour = document.querySelector('.hour');
    var minute = document.querySelector('.minute');
    var second = document.querySelector('.second');
    var inputTime = +new Date('2021-06-11 15:00:00'); //用户输入的时间
    countDown();
    setInterval(countDown, 1000);

    function countDown() {
        var nowTime = +new Date; //返回当前时间总得毫秒数
        var times = (inputTime - nowTime) / 1000; //剩余的秒数
        var d = parseInt(times / 60 / 60 / 24);
        d = d < 10 ? '0' + d : d
        var h = parseInt(times / 60 / 60 % 24);
        h = h < 10 ? '0' + h : h
        hour.innerHTML = h;
        var m = parseInt(times / 60 % 60);
        m = m < 10 ? '0' + m : m
        minute.innerHTML = m;
        var s = parseInt(times % 60);
        s = s < 10 ? '0' + s : s
        second.innerHTML = s;
    }
    //隐藏左右箭头
    var pre = this.document.querySelector('.pre');
    var pro = this.document.querySelector('.pro');
    var main = this.document.querySelector('.main');
    main.addEventListener('mouseenter', function() {
        pre.style.display = 'block';
        pro.style.display = 'block';
        clearInterval(timer);
        timer = null;

    })
    main.addEventListener('mouseleave', function() {
            pre.style.display = 'none';
            pro.style.display = 'none';
            timer = setInterval(function() {
                pro.click();
            }, 2000);

        })
        //轮播图
    var ul = main.querySelector('ul');
    var last = ul.children[0].cloneNode(true);
    ul.appendChild(last);
    var mainWidth = main.offsetWidth;
    var num = 0;
    var flag = true;
    pro.addEventListener('click', function() {
        if (flag) {
            if (num == ul.children.length - 1) {
                ul.style.left = 0;
                num = 0;
            }
            num++;
            // flag = false;
            animate(ul, -num * mainWidth, function() {
                flag = true;
            });
        }

    });
    //左边
    pre.addEventListener('click', function() {
            if (num == 0) {
                num = ul.children.length - 1;
                ul.style.left = 0;
            }
            num--;
            animate(ul, -num * mainWidth);
        })
        //自动播放
    var timer = setInterval(function() {
        pro.click();
    }, 2000);
    //固定定位 返回顶部
    var nav = document.querySelector('.nav');
    var slider = nav.querySelector('.slider');
    document.addEventListener('scroll', function() {
            console.log(window.pageYOffset);
            // //当页面被卷去178就修改侧边栏为固定定位
            // if (window.pageYOffset >= 276) {
            //     slider.style.position = 'fixed';
            // }
        })
        //load时间结束句
})